package com.sky.controller.user;

import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户端套餐浏览接口
 */
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "用户端-套餐浏览接口")
@Slf4j
public class SetmealController {
    
    @Autowired
    private SetmealService setmealService;
    
    /**
     * 根据分类id查询套餐列表
     * @param categoryId 分类id
     * @return 套餐列表
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    public Result<List<SetmealVO>> list(Long categoryId) {
        log.info("用户端根据分类id查询套餐: {}", categoryId);
        // 用户端查询需要返回包含菜品信息的套餐VO列表
        List<SetmealVO> setmealVOList = setmealService.listWithDishes(categoryId);
        return Result.success(setmealVOList);
    }
    
    /**
     * 根据套餐id查询套餐详情
     * @param id 套餐id
     * @return 套餐详情，包含套餐内的菜品信息
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("查询套餐详情")
    public Result<SetmealVO> detail(@PathVariable Long id) {
        log.info("用户端查询套餐详情: {}", id);
        SetmealVO setmealVO = setmealService.getByIdWithDishes(id);
        return Result.success(setmealVO);
    }
}